package appreate.sixnations.quiz;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import appreate.sixnations.quiz.R;
import appreate.sixnations.quiz.utils.Commons;

public class QuizNameToLogo extends SuperQuiz {

	private TextView mNomeNazione;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.quiz);

		init();
		setFlags();
		setFlagWin();
		setCounterTimer(true);

	}

	protected void setFlagWin() {
		double numberDouble = Math.random() * 4;
		int number = (int) numberDouble;

		switch (number) {
		case 0:
			rightAswer = mNameFlag1;
			mNomeNazione.setText(getString(getResources().getIdentifier(mNameFlag1, "string",
					getApplicationInfo().packageName)));
			break;
		case 1:
			rightAswer = mNameFlag2;
			mNomeNazione.setText(getString(getResources().getIdentifier(mNameFlag2, "string",
					getApplicationInfo().packageName)));
			break;
		case 2:
			rightAswer = mNameFlag3;
			mNomeNazione.setText(getString(getResources().getIdentifier(mNameFlag3, "string",
					getApplicationInfo().packageName)));
			break;
		case 3:
			rightAswer = mNameFlag4;
			mNomeNazione.setText(getString(getResources().getIdentifier(mNameFlag4, "string",
					getApplicationInfo().packageName)));
			break;
		default:
			break;
		}

		history.remove(mNameFlag1);
		history.remove(mNameFlag2);
		history.remove(mNameFlag3);
		history.remove(mNameFlag4);
		history.add(rightAswer);

	}

	protected void setFlags() {
		mNameFlag1 = Commons.getInstance().searchFlag(this, history, mMode);
		history.add(mNameFlag1);
		int nameResourceID = getResources().getIdentifier(mNameFlag1, "drawable", getApplicationInfo().packageName);
		mButtonUno.setBackgroundResource(nameResourceID);

		mNameFlag2 = Commons.getInstance().searchFlag(this, history, mMode);
		history.add(mNameFlag2);
		nameResourceID = getResources().getIdentifier(mNameFlag2, "drawable", getApplicationInfo().packageName);
		mButtonDue.setBackgroundResource(nameResourceID);

		mNameFlag3 = Commons.getInstance().searchFlag(this, history, mMode);
		history.add(mNameFlag3);
		nameResourceID = getResources().getIdentifier(mNameFlag3, "drawable", getApplicationInfo().packageName);
		mButtonTre.setBackgroundResource(nameResourceID);

		mNameFlag4 = Commons.getInstance().searchFlag(this, history, mMode);
		history.add(mNameFlag4);
		nameResourceID = getResources().getIdentifier(mNameFlag4, "drawable", getApplicationInfo().packageName);
		mButtonQuattro.setBackgroundResource(nameResourceID);

	}

	protected void init() {
		super.init();

		mNomeNazione = (TextView) findViewById(R.id.nome_nazione);
		mNomeNazione.setTypeface(mTypeface);
	}

	@Override
	protected int getDrawableX(Button button) {
		button.setText("");
		return R.drawable.croix;

	}

	@Override
	protected int getDrawableY(Button button) {
		button.setText("");
		return R.drawable.valider;
	}

	@Override
	protected void decrLife(boolean zero) {
	}

}